
package com.funo.government.info.view;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.funo.government.info.R;

public class HeaderView extends RelativeLayout {

    private Button btnBack;

    private TextView tvTitle;

    private Context mContext;

    private int title;

    public HeaderView(Context context) {
        super(context);
    }

    public HeaderView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        LayoutInflater inflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.header_view, this);
        btnBack = (Button) findViewById(R.id.btnBack);
        tvTitle = (TextView) findViewById(R.id.tvTitle);
        title = attrs.getAttributeResourceValue(null, "Title", -1);
        if (title != -1) {
            tvTitle.setText(getResources().getString(title));
        }

        btnBack.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View paramView) {
                ((Activity) mContext).finish();

            }
        });

    }

    /**
     * 设置标题
     * 
     * @param title
     */
    public void setTitle(String title) {
        tvTitle.setText(title);
    }

    /**
     * 设置标题
     * 
     * @param resId
     */
    public void setTitle(int resId) {
        tvTitle.setText(resId);
    }

    /**
     * 注册标题的点击事件
     * 
     * @param listener
     */
    public void setTitleOnClick(OnClickListener listener) {
        tvTitle.setOnClickListener(listener);
    }

}
